import config from '@/config'
import { initiaStore } from '@/stores/initialization.js'

export async function getChromiums() {
    try {
        if (!config.isWeb) {
            const initiaStores = initiaStore()
            let version = await window.electron.getchromiums()
            let maxversion = {}
            console.log(version);
            
            version.forEach(item => {
                const match = item.version.match(/^(\d+)\./);
                if (match) {
                    item.versionNum = parseFloat(match[1])
                    if (maxversion.path!= undefined) {
                        if (maxversion.versionNum < item.versionNum) {
                            maxversion = item
                        }
                    } else {
                        maxversion = item
                        
                    }
                }
            });
            initiaStores.initiaData.map.Chrome.forEach(item => {
                if (item.value != -1) {
                    let result = version.find(item2 => item2.versionNum == item.value);
                    if (result) {
                        item.path = result.path
                    }
                } else {
                    if (maxversion  != undefined) {
                        item.path = maxversion.path
                    }
                }
            });

        }
    } catch (error) {
        console.log(error);

    }
}